package com.library.controller.user;

import com.library.pojo.Lend;
import com.library.pojo.PageResult;
import com.library.pojo.Result;
import com.library.service.LendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController("userLend")
@RequestMapping("/user/lend")
public class LendController {
    @Autowired
    private LendService lendService;

    /**
     * 借书
     * @param lend
     * @return
     */
    @PostMapping
    public Result lend(@RequestBody Lend lend){
        lendService.lend(lend);
        return Result.success();
    }

    /**
     * 查看自己的借书记录
     */
    @GetMapping("/page")
    public Result pageQuery(@RequestParam(defaultValue = "1") Integer page
            , @RequestParam(defaultValue = "10") Integer pageSize, String bookName,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageResult result = lendService.userPageQuery(page,pageSize,bookName,begin,end);
        return Result.success(result);
    }
}
